import { Component, OnInit, ViewChild, ViewEncapsulation, NgZone } from '@angular/core';
import { I18nService } from '../../core/i18n/i18n.service';
import { DialogConfig, DialogComponent, DialogService, RatingConfig } from 'ngx-weui';
import { ApiService } from 'src/app/core/api';
import { Router, ActivatedRoute } from '@angular/router';
import { MessageService } from 'src/app/core/message.service';
import { StorageService } from 'src/app/core/sotrage/storage.service';

@Component({
	templateUrl: './index.component.html',
	styleUrls: ['./index.component.less'],
})
export class MHComponent implements OnInit {
	list: Array<any> = [];
	user: any = null;
	customIconsAndClassCog: RatingConfig = {
		max: 5,
		stateOff: 'off',
		stateOn: 'on',
		cls: 'rating'
	}
	pageData = {
		pageNo: "1",
		pages: "1",
		name: ''
	}
	constructor(
		private message: MessageService,
		private router: Router,
		private api: ApiService,
		private sto: StorageService
	) {
		this.message.sendMessage('mh');
		this.user = this.sto.get('user')['loginId'];
	}
	ngOnInit() {
		this.getList();
		// this.getMenu();
	}
	onSel(tegId) {
		this.api.post('开始游戏', { id: tegId }).then(res => {
			this.router.navigate(['/gz'], {
				queryParams: res['data']
			});
		})
	}
	onClick(id) {
	}
	isClick = false;
	getList() {
		this.api.post('漫画列表', this.pageData).then(res => {
			this.pageData.pageNo = res['data']['pageNo'];
			this.pageData.pages = res['data']['pages'];
			let lists = res['data']['list'];
			if (res['data']['pageNo'] == 1) {
				this.list = lists;
			} else {
				for (let i = 0; i < lists.length; i++) {
					this.list.push(lists[i]);
				}
			}
			this.test()
		}).catch(res => {
			return res;
		});
	}
	test() {
		for (let i = 0; i < 10; i++) {
			const data = {
				"id": i, //# 漫画编号
				"name": "千与千寻" + i,
				"levelStar": 1.2,
				"providerName": "宫崎骏",
				"briefInfo": "千与千寻漫画简介",
				"isTrade": "Y",//#Y收费，N免费
				"isFinish": "Y",//#Y完结, N未完结
				"thumbnail": "http://127.0.0.1:8213/cartoon/2020-03-06/13/116f5f7bf9554bf9a9e282cb39f0f1ae.jpg",
				"images": "http://127.0.0.1:8213/cartoon/2020-03-06/13/116f5f7bf9554bf9a9e282cb39f0f1ae.jpg,http://127.0.0.1:8213/cartoon/2020-03-06/13/116f5f7bf9554bf9a9e282cb39f0f1ae.jpg,http://127.0.0.1:8213/cartoon/2020-03-06/13/116f5f7bf9554bf9a9e282cb39f0f1ae.jpg",
				"cartoonChapterCount": 12,
				"createTime": "2020-03-10 14:53:40"
			};
			this.list.push(data);
		}
	}
	menus = [];
	getMenu() {
		this.api.post('获取游戏子类列表', {}).then(res => {
			this.menus = res['data']['list'];
		}).catch(res => {
			return res;
		});
	}
}
